<?php
require('fpdf.php');

class PDF extends FPDF
{
    function Header()
    {
        $this->Image('pics\logo.jpg', 10, 5, 15, 15);
        $this->SetFont('Arial','B',16);
        $this->SetTextColor(00, 180, 00);
        $this->Cell(50);
        $this->Cell(50,10,'Automated Employee Management System', 0, 1, 'C');
        $this->Line(10, 25, 200, 25);
    }

    function LoadData($file)//Setup data for populating the table
    {
        $lines = file($file);
        $data = array();
        foreach($lines as $line)
            $data[] = explode(';',trim($line));
        return $data;
    }
    
    function SetProfileHeader($data)//Setup Attendance Report (DATE), Attendance Picture and Employee First Name
    {
        $this->Cell(20,20,'Atendance Report: (Enter Date Here)');
        $this->SetXY(20,28);
        $this->Image('pics\attendance.jpg',10,33,10,10);
        $this->SetFont('Arial','B',12);
        $this->Cell(10, 20, $data['first']."'s". ' Profile');
    }
    
    function SetProfilePicture($data)//Setup Employee Picture, Employee Name and Employee Position
    {
        $this->SetXY(57,38);
        $this->Image('pics\unknown.jpg',20,45,30,30);
        $this->SetTextColor(0,0,55);
        $this->SetFont('Arial','B',16);
        $this->Cell(20, 20, $data['first'].' '.$data['middle'].' '.$data['last']);
        $this->SetXY(57,43);
        $this->SetFont('Arial','B',11);
        $this->SetTextColor(44,44,44);
        $this->Cell(20, 20, $data['position']);
        $this->Line(10, 80, 200, 80);
    }

    function Table($header, $data)
    {
        $this->SetDrawColor(0,0,0);
        $this->SetFont('Arial','B',12);
        $this->SetTextColor(0,0,0);
        $this->Cell(0,7,'August 1-7 (Week 31)',1);
        $this->Ln();
        foreach($header as $col)
        {
            $this->SetFont('Arial','B',11);
            $this->Cell(38,6,$col,1,0,'C');
        }
        $this->Ln();
        $i=0;//Counter for the number of entries
        $week=13;//Counter for the number of weeks
        foreach($data as $row)
        {
            $this->SetFont('Arial','',11);
            foreach($row as $col)
                $this->Cell(38,6,$col,1,0,'C');  
            $this->Ln();
            $i++;
            if($i%7==0)//Check if the reports entered was 7 entries. If so, start a new table
            {
                $this->Ln();
                $this->SetFont('Arial','B',12);
                $this->SetTextColor(0,0,0);
                $this->Cell(0,7,'August 8-14 (Week '.''.$week.')',1);
                $this->Ln(); 
                $week++;  
            }
        }
    }
}

/*Declare Variables Here*/
$profheader = array
    (
    'first'=>'Terence Anton',
    'middle'=>'Chong',
    'last'=>'Dela Fuente',
    'position'=>'System Admin'
    );

$header = array('Date','Time In','Time Out','Overtime Hours','Remarks');

/*End of Declaration*/

/*Main*/
$pdf = new PDF();
$pdf->AddPage();
$file = $pdf->LoadData('bla.txt');
$pdf->SetProfileHeader($profheader);
$pdf->SetProfilePicture($profheader);
$pdf->Ln(45);
$pdf->Table($header, $file);
$pdf->Output();
/*End of Main*/
?>
